<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <pre>
var arr = [
    {id: 1,created: '2016-05-04 15:12:40',content: '1'},
    {id: 2,created: '2016-04-06 15:12:40',content: '2'},
    {id: 3,created: '2016-04-02 15:12:40',content: '3'},
]
将上面数据转换成下面数据格式
方式:(1)使用原生的js
(2)使用lodash
提示
思路:(1)思考转换成下面这种数据结果需要做哪些内容
        分组
        排序
        数据结构
(2)先做最简单内容
需要用到操作:
(1)数组map,sort
(2)lodash的map,group,链式调用
var map = [
    {month: '4月', data: [//(1)按月份分组,并且月份由小到大
        {id: 3,created: '2016-04-02 15:12:40',content: '3'},//(2)按时间排序,由远到近
        {id: 2,created: '2016-04-06 15:12:40',content: '2'}
    ]},
    {month: '5月', data: [
    {id: 1,created: '2016-05-04 15:12:40',content: '1'}
    ]}
]
    </pre>
</body>
<script>
    let arr = [
        {id: 1,created: '2016-05-04 15:12:40',content: '1'},
        {id: 2,created: '2016-04-06 15:12:40',content: '2'},
        {id: 3,created: '2016-04-02 15:12:40',content: '3'},
    ]
    let brr = arr.map(t => {
        let newObject ={}
        let data =[]
        let month =  t.created.charAt(6)
        newObject.month = month + '月'
        data.push(t)
        newObject.data = data
        return newObject
    })
    let crr = []
    for(let i=0;i<brr.length;i++) {
        const item = crr.find(t => brr[i].month ===t.month)
        //存在
        if(item) {
            const index = crr.findIndex(t=> brr[i].month === t.month)
            crr[index].data = [...crr[index].data,...brr[i].data]
            crr[index].data.sort((a,b) => Number(a.created.charAt(9)) - Number(b.created.charAt(9)))
        }//不存在
        else{
            crr.push(brr[i])
        }
    }

    crr.sort(function(a,b) {
        return Number(a.month.charAt(0))  - Number(b.month.charAt(0))
    })
    console.log(crr);
</script>

</html>
